#ifndef TOOLS_H
#define TOOLS_H

#include <opencv2/core/mat.hpp>

#include <QVariantMap>

bool getImgInfo(const cv::Mat &frame , QList<qint16> &m_imageInfo);
void adjustROIInParent(cv::Rect2d& child, const cv::Rect2d& parent);
cv::Mat adjustBoundaryBinaryImage(const cv::Mat& binaryImg);
QString getMacAddress12Chars(const QString &interfaceName, int retryCount = 5, int retryDelayMs = 1000);
bool ensureDirectoryExists(const QString &path);
QString customEncrypt(const QString &plainText, const QString &key);
QString getObfuscatedSerial();
void drawDashedRectangle(cv::Mat &image, int x, int y, int width, int height, int cls);
double calculateStraightness(const std::vector<cv::Point>& points, const cv::Vec4f& line, cv::Point &maxAbovePoint, cv::Point &maxBelowPoint);
cv::Mat rotateImageByFitLine(const cv::Mat& image, const  cv::Vec4f &fitLine);
int findLineDistance(const cv::Mat& image, QVariantList lenthROI, double threshold, double thresholdR, int&leftX, int&rightX, int countThrethon);
void drawLinesOnImage(cv::Mat& image, int leftX, int rightX);
void drawHelperLinesOnImage(cv::Mat& image, double leftX, double rightX);
double calculateMaxGradientDifference(const cv::Mat& rect);
double fitAngleLimited(const cv::Mat& binaryImg);
bool areaisClosed(const QVector<QPointF> &points);
QPolygonF areaconvexHull(const QVector<QPointF> &points) ;
bool areaisRectangleInBounding(const QPolygonF &boundingPolygon, const QRect &rect);
bool isRectangleInPolygon(const QPolygonF &polygon, int left, int top, int right, int bottom);
std::vector<cv::Point> convertQPolygonFToCvPoints(const QPolygonF &polygon);
void drawPolygonsOnImage(cv::Mat &image, const QList<QPolygonF> &polygons);
int countPixelsAboveThreshold(const cv::Mat& mat, double threshold, bool isServon = false);
void drawROIByQList(cv::Mat& drawImage, const QVariantList& lenthROI) ;
bool containsInt(const QVariantList &list, int value);
bool validatePoints(const std::vector<cv::Point2f>& srcPoints, const std::vector<cv::Point2f>& dstPoints);
int findLineDistanceV2(const cv::Mat& image,
                       QVariantList lenthROI ,
                       double threshold, double thresholdR, int&leftX,
                       int&rightX , int countThrethon , int isShow = false);

void saveQVectorToBinary(const QVector<int8_t>& qvec, const std::string& filename) ;
void saveBinaryData(void* data, size_t dataSize, const std::string& baseFilename);
#endif // TOOLS_H
